Geonet: Update to Version 1.#1388
Conversation
|
Please see After all the fix-ups have been made, please make this one clean commit. |
9d95316 to
ca35a2b
Compare
|
Thank you. At a glance, this code needs to use Also the use of Also most of the details that are now in the pull request message concern the commit, not the pull request, so should be in the commit message. Also this removes support for GeoNet version 0 altogether, correct? And the new code prints the version, but does not check that it is version 1, correct? |
|
Also this removes 4 existing tests. |
|
I'll look into using As for the use of This does remove support for GeoNet version 0. There are two things I would point out, one is that GeoNet version 0 was drafted for a preliminary ETSI technical spec (as mentioned in this issue) and a new version was published in 2013 (12 years ago). Second, seeing that GeoNet-related services are rare, and all providers follow current standards I think it's better to remove support for GeoNet version 0 (for simplicity). You are correct, the current PR doesn't check it's version 1... I'll make sure to fix that. In the meantime, can you confirm that it's okay to remove support for GeoNet version 0? I can add it, but don't know if it will be used much. |
|
Thank you for explaining. Regarding the 32-bit TST field, the standard defines it to wrap this often and to have this much precision, it does not include a notion of a calendar date or a wrap counter. It would be wrong for a protocol decoder to present the TS field as if it has more data than it actually has. If the user needs to interpret the recorded 32-bit value of TST relative to "real" date and time, that's what the libpcap packet timestamp is for. So the best this decoder could do is to print TST exactly as it is (an integer number of milliseconds, or something formatted as "seconds.millieconds" or "dd:hh:mm:ss.ms" or whatever is the common notation for this 32-bit value in this practice). Regarding the versions, to comprehend this better, I had a look at the following specifications available at etsi.org:
As far as these documents define it, version 1 did not exist until 2017. As far as I understand V1.2.1 Section 8.4, digital signatures are optional. So, seemingly, version 0 could be not entirely irrelevant, but the problem is, the two version 0 specifications indeed define GeoNet packet structure differently:
This way, I agree that the best move is to lose the current V1.1.1 (version 0) code in the tcpdump decoder, whether anybody gets to implement V1.2.1 (version 0) code in future or not. |
|
Perfect! I've done the following changes;
The GeoNet header has a lot of fields encoded in smaller than 1 byte (i.e., 1-7 bits) values. Achieving pefectly clean code is difficult, since there is a lot of big masking and shifting. |
|
|
||
| const char *next_header_text = basic_header_next_header_text_from_bytes(*next_header); | ||
| version = (value >> (4 + THREE_BYTES)) & FOUR_BITS_MASK; | ||
| if (!memchr(implemented_gn_versions, version, IMPLEMENTED_GN_VERSIONS_NUM)) |
There was a problem hiding this comment.
Please note that memchr(), at least if used this way, does not work as expected on big-endian architectures. A simple if or switch would be sufficient. The same likely applies to NH below.
There was a problem hiding this comment.
Ok! I'll make sure to fix that.
| reserved = (value >> (TWO_BYTES)) & EIGHT_BITS_MASK; | ||
| lt_multiplier = (value >> (2 + ONE_BYTE)) & SIX_BITS_MASK; | ||
| lt_base = (value >> ONE_BYTE) & THREE_BITS_MASK; | ||
| rhl = value & FOUR_BITS_MASK; |
There was a problem hiding this comment.
Fetching the entire header as a 32-bit integer does not work well. One common way to do that would be using a structure, and another would be just fetching one octet at a time, for example:
// Validate that length is at least 4.
uint8_t ver_nh = GET_U_1(*bp);
version = ver_nh & 0xf0;
nh = ver_nh & 0x0f;
*bp++;
*length--;
reserved = GET_U_1(*bp);
*bp++;
*length--;
lt = GET_U_1(*bp);
lt_multiplier = lt & 0x3f;
lt_base = (lt & 0xc0) >> 6;
*bp++;
*length--;
rhl = GET_U_1(*bp);
*bp++;
*length--;There was a problem hiding this comment.
For reference, that's ETSI EN 302 636-4-1 V1.4.1 Section 9.6. It would be useful to say that in a comment before the function to make it clear what it implements.
There was a problem hiding this comment.
Ok! A structure would be great but since there are many <8 bit values I thing going with fetching one octet at a time is better.
Out of curiosity, what do you mean with "Fetching the entire header as a 32-bit integer does not work well."?
There was a problem hiding this comment.
The difference should be easy to see if you compare the complexity of code. Also rhl = value & FOUR_BITS_MASK is wrong because RHL is an 8-bit integer.
|
|
||
| const char *next_header_text = tok2str(common_header_next_header_values, "Unknown", *next_header); | ||
| const char *header_type_text = tok2str(header_type_tok, "Unknown", HT_HST(*header_type, *header_subtype)); | ||
| const char *flags_text = tok2str(flags_text_from_bytes, "Unknown", flags); |
There was a problem hiding this comment.
Likewise, the Common Header should have been a structure or a series of 1-octet and 2-octet fetches, not a 64-bit fetch. Section 9.7 Ibid.
|
Please make it one clean commit and wrap the commit message at 72 columns, "as was the style at the time". |
| if (ndo->ndo_vflag > NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("GN_ADDR:%s tst:%s lat:%u lon:%u pai:%u, s:%u, h:%u; ", process_gn_addr(ndo, gn_addr), process_tst(tst), lat, lon, pai, s, h); | ||
| ND_PRINT("GN_ADDR:%s tst:%u lat:%u lon:%u pai:%u, s:%u, h:%u; ", process_gn_addr(ndo, gn_addr), tst, lat, lon, pai, s, h); |
There was a problem hiding this comment.
Lat, Long and S are signed, please fix. For Lat and Long it may be useful to convert the sign to N/S/E/W. For all three (and H as well) it may be useful to print using a decimal dot to make it easier to read degrees and metres per second. See arista_print_date_hms_time() for an example.
There was a problem hiding this comment.
Fixed too. Also added for PAI (true or false string).
| static const struct tok common_header_next_header_values[] = { | ||
| {0, "Any"}, | ||
| {1, "BTP-A"}, | ||
| {2, "BTP-B"}, |
There was a problem hiding this comment.
Are these 1 and 2 the BTP_A and BTP_B below?
There was a problem hiding this comment.
Yes, they are! I've rearranged the definitions to use the BTP_Aand BTP_B definitions.
| {0, "Any"}, | ||
| {1, "BTP-A"}, | ||
| {2, "BTP-B"}, | ||
| {3, "IPv6"}, |
There was a problem hiding this comment.
Please either terminate every array of struct tok with a { 0, NULL } record or switch to struct uint_tokary and uint2tokary(), otherwise this code will crash.
There was a problem hiding this comment.
Added { 0, NULL } to all struct tok.
| case 3: // 100 seconds | ||
| base_seconds = 100.0; | ||
| break; | ||
| default: // default to 0 second |
There was a problem hiding this comment.
This default case is dead code (LT Base is a 2-bit value). Perhaps this should have been a comment.
There was a problem hiding this comment.
Also the comments for the LT Base values 0, 1, 2 and 3 indicate it would make sense to use named constants.
There was a problem hiding this comment.
Added constants and deleted the dead code.
| base_seconds = 0.0; | ||
| break; | ||
| } | ||
| return (u_int)(base_seconds * lt_multiplier); |
There was a problem hiding this comment.
When LT Base is 50ms, handling LT as an integer (rather than a float) discards any sub-second precision. It would be better to print LT Base and LT Multiplier separately to make it clear what is in the packet (if the product is wrong, it is desirable to know whether the base is off or the multiplier is off or both), after that it may be convenient to print LT (the product) as a decimal with two significant figures after the dot.
There was a problem hiding this comment.
Fixed the float issue. I'm now returning a float and printing out a decimal with two significant figures.
Currently, the LT product is printed out when no verbose level is active. However, for verbose levels greater than 1 both the LT base and LT multiplier are printed out.
| u_int lt_seconds = convert_lt_to_seconds(lt_base, lt_multiplier); | ||
| if (ndo->ndo_vflag == NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("ver:%u nh:%s lt:%us rhl:%u; ", |
There was a problem hiding this comment.
This is what I meant (LT ought to be a float or a string).
| } | ||
| else if (ndo->ndo_vflag > NDO_V_FLAG_FIRST_DEBUG_LEVEL) | ||
| { | ||
| ND_PRINT("ver:%u nh:%s reserved:%u lt:[base:%u mult:%u = %us] rhl:%u; ", |
There was a problem hiding this comment.
And this. Also here LT base could be decoded using tok2str(). Also it may be simpler to print LT using the same format in all cases, unless there is a good reason to make the verbosity granular.
There was a problem hiding this comment.
What are the advantages of decoding LT base with tok2str()?
LT Base is a two bit value used to find the corresponding time value (0.05, 1, 10, 100 seconds) to be used to find the Lifetime of the packet. So having it in str format is only useful for printing purposes.
I agree its simpler to print out the same information. But on the other hand, I think having LT in it's simplest form for low verbosity levels and having the full values of LT for higher verbose levels is better.
infrastation
left a comment
There was a problem hiding this comment.
Well, this is good progress, thank you. This code requires a bit more work before it is ready.
This PR updates ETSI GeoNetworking protocol to version 1 (ETSI EN 302 636-4-1 V1.4.1 (2020-01)). The update includes dissectors for GeoNet Beacon messages and TopoScopeBcast-SH. Additionally, the Basic Transport Protocol (ETSI EN 302 636-5-1 V2.2.1 (2019-05)) has also been updated. It includes BTP-A and BTP-B in all its variants.
50300fe to
6cfc0a9
Compare
|
You could try: |
|
The most recent revision of |
|
Yes! I have a backup of everything. I've rebased my branch with upsteam/master. But I think the PR should be reopened for the changes to take effect. Once that is done I'll make sure to push one clean commit with all the latest fixes. Thank you! |
|
It seems this PR cannot be reopen. |
|
Perhaps not whilst the proposed branch is out of shape. |
|
I see what's happening... after the rebase and force push I changed the commit history and hence "current head isn't a descendant of the stored head sha" (Github Issue). I think the cleanest way to procede would be to open a new PR. What do you think? |
|
If that works for you, please do. Save your work somewhere first of all. Then you can make as many attempts to produce a clean commit in a fresh git clone as necessary. |
|
Before opening a new PR, please [X] the "Allow edits by maintainers" button, to have the "Maintainers are allowed to edit this pull request." flag set. I want to test something. |
|
Hello, last week I opened a new pull request. I added the "Allow edits by mantainers". |
Previous GeoNet was outdated and didn't comply with current standards, making tcpdump wrongly dissect GeoNet packets (issue) .
This PR updates ETSI GeoNetworking protocol to version 1 (ETSI EN 302 636-4-1 V1.4.1 (2020-01)). The update includes dissectors for GeoNet Beacon messages and TopoScopeBcast-SH. Additionally, the Basic Transport Protocol (ETSI EN 302 636-5-1 V2.2.1 (2019-05)) has also been updated. It includes BTP-A and BTP-B in all its variants.